function getXMLHTTPRequestObj(){
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if(window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        return null;
    }
}

function validateTlf(tlf){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/tlf.jsp?req="+tlf,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_tlf").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_tlf").innerHTML = ajax.responseText;
        }
    }
}
function validatePW1(pw){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/pw1.jsp?req="+pw,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_pw1").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_pw1").innerHTML = ajax.responseText;
        }
    }
}
function validatePW2(pw2){
    var ajax = getXMLHTTPRequestObj();
    var pw1 = document.getElementById("pw1").value;
    ajax.open("POST","../NewCustomer/pw2.jsp?pw2="+pw2+"&pw1="+pw1 ,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_pw2").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_pw2").innerHTML = ajax.responseText;
        }
    }
}
function validateFname(fname){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/fname.jsp?req="+fname ,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_fname").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_fname").innerHTML = ajax.responseText;
        }
    }
}
function validateLname(lname){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/lname.jsp?req="+lname,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_lname").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_lname").innerHTML = ajax.responseText;
        }
    }
}
function validateEmail(email){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/email.jsp?req="+email,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_email").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_email").innerHTML = ajax.responseText;
        }
    }
}
function validateStreetname(sn){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/streetname.jsp?req="+sn,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_streetname").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_streetname").innerHTML = ajax.responseText;
        }
    }
}
function validateStreetnumber(sn){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/streetnumber.jsp?req="+sn,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_streetnumber").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_streetnumber").innerHTML = ajax.responseText;
        }
    }
}
function validateZipcode(zipcode){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/zipcode.jsp?req="+zipcode,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_zipcode").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_zipcode").innerHTML = ajax.responseText;
        }
    }
}
function validateCity(city){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/city.jsp?req="+city,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_city").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_city").innerHTML = ajax.responseText;
        }
    }
}
function validateCountry(country){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/country.jsp?req="+country,true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("valid_country").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("valid_country").innerHTML = ajax.responseText;
        }
    }
}

function refreshCaptcha(){
    var ajax = getXMLHTTPRequestObj();
    ajax.open("POST","../NewCustomer/refreshCaptcha.jsp",true);
    ajax.send();
    ajax.onreadystatechange=function(){
        document.getElementById("captcha").innerHTML = ajax.readyState;
        if (ajax.readyState==4 && ajax.status==200){
            document.getElementById("captcha").innerHTML = ajax.responseText;
        }
    }
}